// 统一的成功响应格式
export const success = (data) => {
  return {
    code: 200,
    message: 'success',
    data
  }
}

// 统一的失败响应格式
export const fail = (message, code = 400) => {
  return {
    code,
    message,
    data: null
  }
}

// 分页数据处理
export const handlePagination = (list, page, pageSize) => {
  const start = (page - 1) * pageSize
  const end = start + pageSize
  return {
    list: list.slice(start, end),
    pagination: {
      page,
      pageSize,
      total: list.length
    }
  }
}

// 日期格式化
export const formatDate = (date) => {
  if (!date) return ''
  const d = new Date(date)
  return d.toLocaleString('zh-CN', {
    year: 'numeric',
    month: '2-digit',
    day: '2-digit',
    hour: '2-digit',
    minute: '2-digit',
    second: '2-digit',
    hour12: false
  }).replace(/\//g, '-')
}

// 生成随机ID
export const generateId = () => {
  return Math.floor(Math.random() * 10000000)
}

// 深度克隆对象
export const deepClone = (obj) => {
  if (obj === null || typeof obj !== 'object') return obj
  const clone = Array.isArray(obj) ? [] : {}
  for (let key in obj) {
    if (Object.prototype.hasOwnProperty.call(obj, key)) {
      clone[key] = deepClone(obj[key])
    }
  }
  return clone
} 